# 定义水果类, 创建苹果, 橘子, 西瓜三个对象。分别添加属性: 品种、颜色和价格。 输出对应信息

# class Fruits(object):
#     def __init__(self, variety, color, price):
#         self.variety = variety
#         self.color = color
#         self.price = price
#
#     def __str__(self):
#         return f"人在吃{self.color}的{self.variety}，价格是：{self.price}元"
#
#
# apple = Fruits("苹果", "红色", 5)
# orange = Fruits("橘子", "黄色", 2)
# watermelon = Fruits("西瓜", "绿色", 8)
# print(apple)
# print(orange)
# print(watermelon)

# 定义电脑类, 有品牌、价格属性。能够播放音乐 或 电影。创建 "联想电脑" 和 "苹果电脑"，联想电脑播放音乐《光年之外》, 苹果电脑播放电影 《黑寡妇》
# class Computer(object):
#     def __init__(self, brand, price, music):
#         self.brand = brand
#         self.price = price
#         self.music = music
#
#     def play(self):
#         print(f"人在使用电脑欣赏{self.music}")
#
#
# computer1 = Computer("联想电脑", 4000, "《光年之外》")
# computer2 = Computer("苹果电脑", 6000, "《黑寡妇》")
#
# computer1.play()
# computer2.play()


# 1. 公交车类(Bus)，有车型(type_name), 限员数(member_count) 作为属性
#
# 2. 乘客类(Person)，拥有名字(name) 作为属性
#
# 3. 公交车支持上(add_bus)、下(sub_bus)车,  修改乘客列表(member_list),车内人数num
#
# 4. 要求上下乘客后, 打印车辆信息: 类型, 限员数, 乘客列表
#
#    提示: 上车需要 判断 是否有空余位置!
# class Bus(object):
#     def __init__(self, type_name, member_count):
#         self.type_name = type_name
#         self.member_count = member_count
#         self.member_list = []
#
#     def __str__(self):
#         return f"类型：{self.type_name}，限员数：{self.member_count}人乘车列表有：{self.member_list}"
#
#     def add_bus(self, person):
#         num = len(self.member_list)
#         if num < self.member_count:
#             self.member_list.append(person.name)
#         else:
#             print("已满员，请乘坐下一辆车")
#
#     def sub_bus(self,person):
#         self.member_list.remove(person.name)
#
#
# class Person(object):
#     def __init__(self, name):
#         self.name = name
#
#     def __str__(self):
#         return f"{self.name}"
#
#
# person1 = Person("小明")
# person2 = Person("小红")
# print(person1)
# print(person2)
#
# bus = Bus("大巴", 1)
# print(bus)
#
# bus.add_bus(person1)
# print(bus)
# bus.add_bus(person2)
# print(bus)









# 1. 公交车类(Bus)，
# 有车型(type_name), 限员数(member_count) 作为属性
#
# 2. 乘客类(Person)，拥有名字(name) 作为属性
#
# # 3. 公交车支持上(add_bus)、下(sub_bus)车,  修改乘客列表(member_list),车内人数num
# #
# # 4. 要求上下乘客后, 打印车辆信息: 类型, 限员数, 乘客列表
# #
# #    提示: 上车需要 判断 是否有空余位置!
# class Bus(object):
#     def __init__(self,type_name,member_count):
#         self.type_name =type_name
#         self.member_count = member_count
#         self.member_list = []
#
#     def __str__(self):
#         return f"{self.type_name},限员数:{self.member_count},乘车列表{self.member_list}"
#
#     def add_bus(self,person):
#         num = len(self.member_list)
#         if num < self.member_count:
#             self.member_list.append(person.name)
#         else:
#             print("已满员，请乘坐下辆列车")
#
#     def sub_bus(self,person):
#         self.member_list.remove(person.name)
#
# class Person(object):
#     def __init__(self,name):
#         self.name = name
#
#     def __str__(self):
#         return f"{self.name}"
#
#
# xiaoming = Person("小明")
# xiaohong = Person("小红")
# print(xiaoming)
# print(xiaohong)
#
# bus = Bus("小型客车",1)
# print(bus)
#
#
# bus.add_bus(xiaoming)
# print(bus)
# bus.add_bus(xiaohong)
# print(bus)



class Bus(object):
    def __init__(self,type_name,member_count):
        self.type_name =type_name
        self.member_count = member_count
        self.free_seat = member_count
        self.member_list = []

    def __str__(self):
        return f"{self.type_name},限员数:{self.member_count},乘车列表{self.member_list}"

    def add_bus(self,person):
        if self.free_seat >=1:

            self.member_list.append(person.name)
            self.free_seat -= 1
        else:
            print("已满员，请乘坐下辆列车")

    def sub_bus(self,person):
        self.free_seat += 1
        self.member_list.remove(person.name)


class Person(object):
    def __init__(self,name):
        self.name = name

    def __str__(self):
        return f"{self.name}"


xiaoming = Person("小明")
xiaohong = Person("小红")
xiaobai = Person("小白")

bus = Bus("小型客车",2)
print(bus)


bus.add_bus(xiaoming)
print(bus)
bus.add_bus(xiaohong)
print(bus)
bus.add_bus(xiaobai)
print(bus)


































